package cn.itcast.zt.example.syncContainer;

import java.util.Iterator;
import java.util.Vector;

/**
 * 同步容器
 * create by zhangtian on 2018/4/8
 */
public class VectorExample3 {// 请求总数

    private static void test1(Vector<Integer> v1){ // foreach
        for(Integer i : v1 ){
            if(i.equals(3)){
                v1.remove(i) ;
            }
        }
    }

    private static void test2(Vector<Integer>  v1){ // foreach
        Iterator<Integer> it = v1.iterator() ;
        while(it.hasNext()){
            Integer i = it.next() ;
            if(i.equals(3)){
                v1.remove(i) ;
            }
        }
    }

    private static void test3(Vector<Integer>  v1){ // foreach
        for(int i = 0; i < v1.size(); i++ ){
            if(v1.get(i).equals(3)){
                v1.remove(i) ;
            }
        }
    }

    public static void main(String[] args) throws Exception {
        Vector<Integer> vector = new Vector<>();
        vector.add(1);
        vector.add(2);
        vector.add(3);
        test3(vector);
    }
}
